package servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.Docente;
import beans.listas.SolicitudInforme;
import dao.interfaces.DocenteDAO;
import dao.interfaces.SolicituddccDAO;
import factory.Factory;

/**
 * Servlet implementation class SGenerarInformeDisp
 */
@WebServlet("/SGenerarInformeDisp")
public class SGenerarInformeDisp extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Servlet Informe");
		String accion = request.getParameter("accion");
		System.out.println(accion);
		if (accion.equals("Listar")) {
			Listar(request, response);
		}else if (accion.equals("BuscarDocentes")) {
			ListarDocentes(request, response);
		}
		else if (accion.equals("BuscarDocentesfiltro")) {
			ListarDocentesFiltro(request, response);
		}
	}
	
	protected void Listar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Factory fac = Factory.obtenerTipo(Factory.MySql);
		SolicituddccDAO sdao = fac.obtenerSolicituddccDAO();
		
		List<SolicitudInforme> lista = sdao.ListarSolInformeDisp();
		
		HttpSession session = request.getSession();
		session.setAttribute("ListaSol", lista);
		request.getRequestDispatcher("tbsoliinf.jsp").forward(request, response);
	}
	
	protected void ListarDocentesFiltro(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Factory fac = Factory.obtenerTipo(Factory.MySql);
		
		String esp = request.getParameter("esp");
		
		System.out.println(esp);
		DocenteDAO sdao = fac.obtenerDocenteDAO();
		
		List<Docente> lista = sdao.listarDocentesBuscarFiltro(esp);
		
		HttpSession session = request.getSession();
		session.setAttribute("ListaDoc", lista);
		request.getRequestDispatcher("frm_buscar_docente.jsp").forward(request, response);
	}
	
	protected void ListarDocentes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Factory fac = Factory.obtenerTipo(Factory.MySql);
		
		DocenteDAO sdao = fac.obtenerDocenteDAO();
		
		List<Docente> lista = sdao.listarDocentesBuscar();
		
		HttpSession session = request.getSession();
		session.setAttribute("ListaDoc", lista);
		request.getRequestDispatcher("frm_buscar_docente.jsp").forward(request, response);
	}


}
